Page({
  data: {
    direction: 180
  },
  onLoad(options) {
    wx.startCompass()
  },
  onShow() {
    var that = this
    wx.onCompassChange(function (res) {
      var direction = res.direction
      direction = 360 - direction
      that.setData({
        direction: direction
      })
    })
  },
  onHide() {
    wx.offCompassChange()
  },
  onUnload() {
    wx.stopCompass()
  }
})